package com.deer.wms.base.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.deer.wms.base.system.dao.SupplierManageMapper;
import com.deer.wms.base.system.model.Supplier.SupplierManage;
import com.deer.wms.base.system.model.Supplier.SupplierManageCriteria;
import com.deer.wms.base.system.model.Supplier.SupplierManageDto;
import com.deer.wms.base.system.service.SupplierManageService;
import com.deer.wms.project.root.service.SuperServiceImpl;
import com.deer.wms.project.root.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by guo on 2019/11/21.
 */
@Service
@Transactional
public class SupplierManageServiceImpl extends SuperServiceImpl<SupplierManageMapper, SupplierManage> implements SupplierManageService {

    @Autowired
    private SupplierManageMapper supplierManageMapper;

    @Autowired
    private RedisUtil redisUtil;

    @Override
    public List<SupplierManageDto> findByCode(String supplierCode) {
        return supplierManageMapper.findByCode(supplierCode);
    }

    @Override
    public List<SupplierManageDto> findByName(String supplierName) {
        return supplierManageMapper.findByName(supplierName);
    }

    @Override
    public List<SupplierManageDto> findList(SupplierManageCriteria criteria) {
        return supplierManageMapper.findList(criteria);
    }


    @Override
    public void deleteBySupplierCode(String supplierCode) {
        supplierManageMapper.deleteBySupplierCode(supplierCode);
    }

    @Override
    public SupplierManage findBy(String field, String value) {
        QueryWrapper<SupplierManage> qw = new QueryWrapper<>();
        return getOne(qw.eq(field, value));
    }

    public boolean save(SupplierManage supplierManage){
        super.save(supplierManage);
        redisUtil.remove("allSupplierManage");
        return true;
    }

    public void deleteById(Integer supplierManageId){
        super.removeById(supplierManageId);
        redisUtil.remove("allSupplierManage");
    }

    public void update(SupplierManage supplierManage){
        super.updateById(supplierManage);
        redisUtil.remove("allSupplierManage");
    }
}
